package com.sense.kukoo.common.repo.kv.user

import android.text.TextUtils
import com.sense.kukoo.common.repo.http.bean.UserInfoBean
import com.sense.kukoo.common.repo.kv.KukooKeyValueManager
import com.sense.kukoo.lib_logger.LoggerManager
import com.tencent.mmkv.MMKV

class UserImpl(val mmkv: MMKV):User {

    override fun setUser(b: UserInfoBean?) {
        LoggerManager.d("User.setUser=${b}")
        mmkv.encode(KukooKeyValueManager.KEY_USER, b)
    }

    override fun get(): UserInfoBean? = mmkv.decodeParcelable(KukooKeyValueManager.KEY_USER, UserInfoBean::class.java)

    override fun userName():String {
        val mUser = mmkv.decodeParcelable(KukooKeyValueManager.KEY_USER, UserInfoBean::class.java)
        if(!TextUtils.isEmpty(mUser?.channelName)){
            return mUser!!.channelName
        } else {
            return ""
        }
    }

}